package ${package.ServiceImpl};

import org.springframework.beans.BeanUtils;
import ${package.Entity}.*;
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import ${cfg.packagePath}.common.model.PageReq;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Autowired
    private ${table.mapperName} ${(table.mapperName)?uncap_first};

    /**
    * 查询${table.comment!}数据
    */
    @Override
    public List<${entity}DTO> list(${entity}SearchReq req) {
        List<${entity}DTO> list = ${(table.mapperName)?uncap_first}.list(req);

        return list;
    }

    /**
    * 查询${table.comment!}分页数据
    */
    @Override
    public IPage<${entity}DTO> page(${entity}SearchReq req, PageReq pageReq){
        IPage<${entity}DTO> iPage = ${(table.mapperName)?uncap_first}.list(req, pageReq.getPage());

        return iPage;
    }

    /**
    * 新增${table.comment!}
    */
    @Override
    @Transactional
    public void add(${entity}AddReq req){
        ${entity} ${entity?uncap_first} = new ${entity}();
        BeanUtils.copyProperties(req, ${entity?uncap_first});

        ${(table.mapperName)?uncap_first}.insert(${entity?uncap_first});
    }

    /**
    * 删除${table.comment!}
    */
    @Override
    @Transactional
    public void delete(Long id){
        ${entity} ${entity?uncap_first} = new ${entity}();
        ${entity?uncap_first}.setId(id);
        ${entity?uncap_first}.setIsDelete((short) 1);

        ${(table.mapperName)?uncap_first}.updateById(${entity?uncap_first});
    }

    /**
    * 更新${table.comment!}
    */
    @Override
    @Transactional
    public void update(${entity}UpdateReq req){
        ${entity} ${entity?uncap_first} = new ${entity}();
        BeanUtils.copyProperties(req, ${entity?uncap_first});

        ${(table.mapperName)?uncap_first}.updateById(${entity?uncap_first});
    }

    /**
    * 根据id查询${table.comment!}
    */
    @Override
    public ${entity}DTO getById(Long id){
        ${entity}DTO ${entity?uncap_first}DTO = ${(table.mapperName)?uncap_first}.getById(id);

        return ${entity?uncap_first}DTO;
    }

}
</#if>
